home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / myPlatform demo ƒ / sMovPlatform.p < prev    next >
Text File  |  1995-01-16  |  3KB  |  112 lines

  1. { Platform sprite, moveable version, not faceless }
  2.  
  3. unit sMovPlatForm;
  4.  
  5. interface
  6.  
  7.     uses
  8. {$IFC UNDEFINED THINK_PASCAL}
  9.         Types, Quickdraw,
  10. {$ENDC}
  11.         SAT, sPlatForm;
  12.  
  13.     var
  14.         platFace: FacePtr;
  15.  
  16.     procedure InitMovPlatForm;
  17.     procedure SetupMovPlatForm (me: SpritePtr);
  18.     procedure HandleMovPlatForm (me: SpritePtr);
  19.     procedure HitMovPlatForm (me, him: SpritePtr);
  20.  
  21. implementation
  22.  
  23.     procedure InitMovPlatForm;
  24.         var
  25.             i: integer;
  26.     begin
  27.         platFace := SATGetFace(138);
  28.     end;
  29.  
  30.     procedure SetupMovPlatForm (me: SpritePtr);
  31.         var
  32.             r: Rect;
  33.             pol: PolyHandle;
  34.     begin
  35.         me^.speed.v := -1 + SATRand(2) * 2;
  36.         {me^.kind := -2; {Enemy kind}
  37.         me^.face := platFace;
  38.         SetRect(me^.hotRect, 0, 3, 60, 20);
  39.         me^.task := @HandleMovPlatform;
  40.         me^.hittask := @HitMovPlatform;
  41.     end;
  42.  
  43.     procedure HandleMovPlatForm (me: SpritePtr);
  44.     begin
  45.         me^.position.v := me^.position.v + me^.speed.v;
  46.         if me^.position.v < 40 then
  47.             me^.speed.v := 1;
  48.         if me^.position.v > gSAT.offSizeV - 32 then
  49.             me^.speed.v := -1;
  50.  
  51. {Move}
  52.         if me^.speed.v = 0 then
  53.             if me^.position.v > gSAT.offSizeV div 2 then
  54.                 me^.speed.v := -1
  55.             else
  56.                 me^.speed.v := 1;
  57.  
  58.         me^.layer := -me^.position.v;
  59.     end;
  60.  
  61.     procedure HitMovPlatForm;
  62.         var
  63.             mini, i, min: integer;
  64.             diff: array[1..4] of integer;
  65.     begin
  66.         if him^.Task <> @HandlePlatForm then {check for HandleMovPlatForm too?}
  67.             begin
  68.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);{TtoB}
  69.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);{BtoT}
  70.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);{LtoR}
  71.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);{RtoL}
  72.                 mini := 0;
  73.                 min := 10000;
  74.                 for i := 1 to 4 do
  75.                     if min > diff[i] then
  76.                         begin
  77.                             min := diff[i];
  78.                             mini := i;
  79.                         end;
  80.                 case mini of
  81.                     1: {floor}
  82.                         begin
  83.                             him^.position.v := him^.position.v - diff[1] + 2;
  84.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  85.                             if him^.speed.v > 0 then
  86.                                 him^.speed.v := 0;
  87.                         end;
  88.                     2: {cieling (sp?)}
  89.                         begin
  90.                             him^.position.v := him^.position.v + diff[2] + 1;
  91. {No signal here}
  92.                             if him^.speed.v < 0 then
  93.                                 him^.speed.v := -him^.speed.v;
  94.                         end;
  95.                     3: {left}
  96.                         begin
  97.                             him^.position.h := him^.position.h - diff[3] - 1;
  98.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  99.                             if him^.speed.h > 0 then
  100.                                 him^.speed.h := -him^.speed.h;
  101.                         end;
  102.                     4: {right}
  103.                         begin
  104.                             him^.position.h := him^.position.h + diff[4] + 1;
  105.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  106.                             if him^.speed.h < 0 then
  107.                                 him^.speed.h := -him^.speed.h;
  108.                         end;
  109.                 end;{case}
  110.             end; {if}
  111.     end; {HitMovPlatForm}
  112. end.{of unit}